package com.yuufa.test.graph;

public class PascalMain {

    public static void main(String[] args) {
        int n = 5;
        
        for (int i = 1; i <= n; i++) {
            for (int j = n; j > i; j--) {
                System.out.printf("%3s","");
            }
            for (int j = 1; j <= i; j++) {
                System.out.printf("%6d", combi(i - 1, j - 1));
            }
            for (int j = n; j > i; j--) {
                System.out.printf("%3s","");
            }
            System.out.println();
        }
    }

    public static long combi(int n, int r) {
        int i;
        long p = 1;

        for (i = 1; i <= r; i++)
            p = p * (n - i + 1) / i;

        return p;
    }
}
